/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.discount.web.controller.manager;


import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.discount.api.entity.Coupon;
import com.medusa.gruul.discount.api.model.dto.manager.CouponDto;
import com.medusa.gruul.discount.api.model.param.manager.CouponParam;
import com.medusa.gruul.discount.api.model.vo.manager.CouponSimpleVo;
import com.medusa.gruul.discount.api.model.vo.manager.CouponVo;
import com.medusa.gruul.discount.api.model.vo.manager.RecycleCouponVo;
import com.medusa.gruul.discount.service.manager.ICouponService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠劵 前端控制器
 * </p>
 *
 * @author lcysike
 * @since 2019-12-09
 */
@RestController
@RequestMapping("/manager/coupon")
public class CouponController {

    @Autowired
    private ICouponService couponService;

    /**
     * 优惠劵信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "优惠劵信息列表")
    public Result<PageUtils<CouponVo>> getCouponList(CouponParam couponParam) {
        PageUtils<CouponVo> pageUtils = new PageUtils(couponService.getCouponList(couponParam));
        return Result.ok(pageUtils);
    }

    /**
     * 回收券信息列表
     */
    @GetMapping("/recycle/list")
    @ApiOperation(value = "回收券列表")
    public Result<List<RecycleCouponVo>> getRecycleList() {
        List<RecycleCouponVo> recycleList = couponService.getRecycleList();
        return Result.ok(recycleList);
    }


    /**
     * 积分优惠劵信息列表
     */
    @GetMapping("/integral/list")
    @ApiOperation(value = "积分优惠劵信息列表")
    public Result<PageUtils<CouponVo>> getIntegralCouponList(CouponParam couponParam) {
        PageUtils<CouponVo> pageUtils = new PageUtils(couponService.getIntegralCouponList(couponParam));
        return Result.ok(pageUtils);
    }

    /**
     * 获取单张优惠劵信息
     */
    @GetMapping("/get/{id}")
    @ApiOperation(value = "单张优惠劵信息")
    public Result<CouponSimpleVo> getSimpleCoupon(@ApiParam(value = "优惠劵id", required = true) @PathVariable("id") Long id) {
        CouponSimpleVo couponSimpleVo = couponService.getSimpleCoupon(id);
        return Result.ok(couponSimpleVo);
    }

    /**
     * 赠送优惠劵
     */
    @PostMapping("/give/{ids}")
    @ApiOperation(value = "赠送优惠劵")
    public Result giveCoupon(@ApiParam(value = "优惠劵信息list", required = true) @RequestBody List<CouponDto> couponDtos,
                             @ApiParam(value = "用户ids", required = true) @PathVariable(name = "ids") String[] ids) {
        couponService.giveCoupon(couponDtos, ids);
        return Result.ok();
    }

    /**
     * 优惠劵新增
     */
    @PostMapping("/add")
    @ApiOperation(value = "优惠劵新增")
    public Result addCoupon(@RequestBody @Validated CouponDto couponDto) {
        couponService.addCoupon(couponDto);
        return Result.ok();
    }

    /**
     * 优惠劵修改
     */
    @PutMapping("/update")
    @ApiOperation(value = "优惠劵修改")
    public Result updateCoupon(@RequestBody @Validated CouponDto couponDto) {
        couponService.updateCoupon(couponDto);
        return Result.ok();
    }

    /**
     * 关闭/启用优惠劵
     */
    @PutMapping("/changeStatus/{status}")
    @ApiOperation(value = "关闭/启用优惠劵")
    public Result changeCouponStatus(@ApiParam(value = "优惠劵ids", required = true) @RequestBody Long[] ids,
                                     @ApiParam(value = "优惠劵状态值", required = true) @PathVariable("status") Integer status) {
        couponService.changeCouponStatus(ids, status);
        return Result.ok();
    }

    /**
     * 优惠劵删除
     */
    @DeleteMapping("/delete/{ids}")
    @ApiOperation(value = "优惠劵删除(单个与批量共用)")
    public Result deleteCouponList(@ApiParam(value = "优惠劵ids", required = true) @PathVariable(name = "ids") Long[] ids) {
        couponService.deleteCouponList(ids);
        return Result.ok();
    }
}
